'''
考勤管理
'''
from Lib.base.page_object.attendance.attendance_group import AttendanceGroup
from selenium.webdriver.common.by import By
import allure
from Lib.common.assert_class import AssertClass
import pytest
from Lib.common.get_data_by_mysql import MysqlAssert


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestAttendance.assertClass = AssertClass(login)
    TestAttendance.group = AttendanceGroup(login)


@allure.feature("考勤管理功能测试")
class TestAttendance:

    @classmethod
    def teardown_class(cls):
        # 删除考勤组信息
        delete_group_sql = 'DELETE g FROM info_work_group  g WHERE g.name LIKE "UI%"'
        MysqlAssert().delete_data_by_sql(delete_group_sql)

    @allure.story("考勤组管理")
    @allure.title('考勤组新增、编辑、关闭和重启')
    @pytest.mark.skip
    def test_1_attendance_group(self):
        '''
        新增告警阀值
        :return:
        '''
        with allure.step('新增考勤组'):
            self.group.add_attendance_group()
            # 设置断言
            assert_arg = (By.XPATH, '//p[contains(text(), "考勤组更新成功")]')
            self.assertClass.make_assert_by_text(args=assert_arg, assert_data='考勤组更新成功')
        with allure.step('查看和编辑考勤组'):
            self.group.attendance_group_detail_and_update()
            # 设置断言
            assert_arg = (By.XPATH, '//p[contains(text(), "考勤组更新成功")]')
            self.assertClass.make_assert_by_text(args=assert_arg, assert_data='考勤组更新成功')
        with allure.step('停止和重启考勤组'):
            self.group.attendance_group_stop_and_open()
            # 设置断言
            assert_arg = (By.XPATH, '//p[contains(text(), "重启成功")]')
            self.assertClass.make_assert_by_text(args=assert_arg, assert_data='重启成功')


if __name__ == '__main__':
    pytest.main(
        ['-v', '-s',
         './attendance_manage_test.py::TestAttendance'])
    # pytest.main(['-v', './alert_setting_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
